package abaco.gui.textfield.listener;

import java.awt.Color;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import abaco.gui.Manager;
import abaco.gui.Menuable;
import abaco.gui.Panel;

public class MouseListener extends MouseAdapter{

	public static final Color DESELECT = new Color(Color.WHITE.getRGB());
	public static final Color SELECT   = new Color(Color.LIGHT_GRAY.getRGB());
	protected Component component;

	public MouseListener(Component comp) {
		this.component = comp;
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		System.out.println("clicked mouse");
		if(e.getClickCount() == 2) {
			component.setBackground(SELECT);
			Manager.getInstance().setCurrentFocused(component);
		}
		
		if ((e.getModifiers() & MouseEvent.BUTTON3_MASK) != 0) {  
            Panel panel = (Panel) component;
			if(panel.getSymbol() instanceof Menuable) {
            	Menuable menuable = (Menuable) panel.getSymbol();
            	((Menuable)panel.getSymbol()).getMenu().show(panel, e.getX(), e.getY());
            }
        }
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		System.out.println("enteded mouse");
		//TODO acho que só devemos tirar a seleção com o ESC do teclado
		//this.textField.setBackground(DESELECT);
	}

	@Override
	public void mouseExited(MouseEvent e) {
		System.out.println("exited mouse");
		//TODO acho que só devemos tirar a seleção com o ESC do teclado
		//this.textField.setBackground(DESELECT);
	}
}
